/**
 *
 */
package com.longrise.android.byjk.utils;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;

import com.longrise.android.byjk.R;
import com.longrise.common.utils.AppUtil;

/**
 * simple introduction
 * <p>
 * <p>
 * detailed comment
 *
 * @author Administrator 2015-12-29
 * @see
 * @since 1.0
 */
public class DialogUtil {

    private static final DialogUtil dialogUtil = new DialogUtil();

    private Dialog mDialog;

    private DialogUtil() {

    }

    public static DialogUtil getInstance() {
        return dialogUtil;

    }

    public void dismiss() {
        if (mDialog != null) {
            mDialog.dismiss();
            mDialog = null;
        }
    }

    /**
     * 获得一个
     */
    public Dialog creatAlertDialog(Context context, View view, int width, int height) {
        if (mDialog != null && mDialog.isShowing()) {
            dismiss();
        }
        mDialog = new Dialog(context, R.style.VideoListDialog);
        mDialog.show();
        width = AppUtil.dip2px(width);
        height = AppUtil.dip2px(height);
        mDialog.getWindow().setContentView(view, new LayoutParams(width, height));
        mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        mDialog.setCanceledOnTouchOutside(false);
        return mDialog;
        
        /*WindowManager.LayoutParams params = mDialog.getWindow().getAttributes();
        params.width = ScreenUtil.dip2px(context, 266);
        params.height = ScreenUtil.dip2px(context, 126);
        mDialog.getWindow().setAttributes(params);
        mDialog.getWindow().clearFlags(
                WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);*/
    }

    public void isDataNetWorkPlayer(final Intent intent, final Context cxt) {
        View v = View.inflate(cxt, R.layout.dialog_exit, null);
        final TextView text_Cacnle = (TextView) v.findViewById(R.id.text_cancle);
        final TextView text_Confrim = (TextView) v.findViewById(R.id.text_confirm);
        final TextView hint = (TextView) v.findViewById(R.id.dialog_hint);
        hint.setText("提示");
        final TextView msg = (TextView) v.findViewById(R.id.text_m);
        msg.setText("您当前处于非wifi网络环境下，继续使用可能产生流量");
        View.OnClickListener listener = new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                switch (view.getId()) {
                    case R.id.text_cancle:
                        break;

                    case R.id.text_confirm:
                        cxt.startActivity(intent);
                        break;
                }
                DialogUtil.getInstance().dismiss();
            }
        };
        text_Cacnle.setOnClickListener(listener);
        text_Confrim.setOnClickListener(listener);
        DialogUtil.getInstance().creatAlertDialog(cxt, v, 266, 159);
    }

}
